import { createRouter, createWebHashHistory } from 'vue-router';
import { setupRouterGuards } from './guard';

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      redirect: '/course',
      meta: {
        title: '首页',
      },
    },
    {
      path: '/course',
      name: 'course',
      component: () => import('../views/course/index.vue'),
      meta: {
        title: '课程',
        requiresAuth: true,
      },
    },
    {
      path: '/user-center',
      name: 'user-center',
      component: () => import('../views/userCenter/index.vue'),
      meta: {
        title: '个人中心',
        requiresAuth: true,
      },
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/index.vue'),
      meta: {
        title: '用户登录',
        guestOnly: true,
      },
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/register/index.vue'),
      meta: {
        title: '用户注册',
        guestOnly: true,
      },
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'not-found',
      redirect: '/',
      meta: {
        title: '页面未找到',
      },
    },
  ],
});

// 安装路由守卫
setupRouterGuards(router);

export default router;
